package com.study.day1;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

/**
 * 剑指 Offer 09. 用两个栈实现队列
 */
class Solution30 {

    static class MinStack {
        Stack<Integer> A, B;
        public MinStack() {
            A = new Stack<>();
            B = new Stack<>();
        }

        public void push(int x) {
            A.add(x);
            if (B.empty() || B.peek() >= x) {
                B.add(x);
            }
        }
        public void pop() {
            if (A.pop().equals(B.peek())) {
                B.pop();
            }
        }
        public int top() {
            return A.peek();

        }
        public int min() {
            return B.peek();
        }


    }

    public static void main(String[] args) {
        // ====== Driver Code ======
        List<Integer> res = new ArrayList<>();
        MinStack minStack = new MinStack();
        minStack.push(-2);
        minStack.push(0);
        minStack.push(-3);
        res.add(minStack.min());
        minStack.pop();
        res.add(minStack.top());
        res.add(minStack.min());
        System.out.println(Arrays.toString(res.toArray()));

    }
}

